package com.ldg.shop.controller;

import com.ld.utils.PageUtils;
import com.ld.pojo.R;

import com.ldg.shop.entity.GoodsEntity;
import com.ldg.shop.group.Goods;
import com.ldg.shop.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 商品管理
 *
 * @author LD
 * @email 419631142@qq.com
 * @date 2022-09-12 18:39:32
 */
@RestController
@RequestMapping("goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = goodsService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 根据id查找
     */
    @GetMapping("/FindById/{id}")
    public R FindById(@PathVariable String id){
        Goods goods = goodsService.FindById(id);
        return R.ok().put("goods", goods);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
		GoodsEntity goods = goodsService.getById(id);
        return R.ok().put("goods", goods);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody Goods goods){
		goodsService.save(goods);
        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody Goods goods){
		goodsService.updateById(goods);
        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody String[] ids){
		goodsService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
